#include "../../mqserver/channel.hpp"
#include <gtest/gtest.h>

MyRabbitMQ::ChannelManager::ptr channels;

class ChannelTest : public testing::Environment
{
    virtual void SetUp() override
    {
        channels = std::make_shared<MyRabbitMQ::ChannelManager>();
    }

    virtual void TearDown() override
    {

    }
};

//创建信道测试
TEST(ChannelTest,create_test)
{
    channels->openChannel("channel-1",
    muduo::net::TcpConnectionPtr(),
    MyRabbitMQ::ProtobufCodecPtr(),
    threadpool::ptr(),
    std::make_shared<MyRabbitMQ::VirtualHost>("host-1","./data1.db","./message1"),
    std::make_shared<MyRabbitMQ::ConsumerManager>());

    channels->openChannel("channel-2",
    muduo::net::TcpConnectionPtr(),
    MyRabbitMQ::ProtobufCodecPtr(),
    threadpool::ptr(),
    std::make_shared<MyRabbitMQ::VirtualHost>("host-2","./data2.db","./message2"),
    std::make_shared<MyRabbitMQ::ConsumerManager>());

    channels->openChannel("channel-3",
    muduo::net::TcpConnectionPtr(),
    MyRabbitMQ::ProtobufCodecPtr(),
    threadpool::ptr(),
    std::make_shared<MyRabbitMQ::VirtualHost>("host-3","./data3.db","./message3"),
    std::make_shared<MyRabbitMQ::ConsumerManager>());
}

//关闭信道测试
TEST(ChannelTest,close_test)
{
    channels->closeChannel("channel-3");
}

//获取信道测试
TEST(ChannelTest,get_test)
{
    auto ptr1 = channels->getChannnel("channel-3");
    ASSERT_EQ(ptr1,MyRabbitMQ::Channel::ptr());

    auto ptr2 = channels->getChannnel("channel-2");
    ASSERT_EQ(ptr2 == MyRabbitMQ::Channel::ptr(),false);
}


int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new ChannelTest);
    int ret = RUN_ALL_TESTS();
    return 0;
}

